package com.weitu.worklicense.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.worklicense.entity.GroundLicense;
import com.weitu.worklicense.mapper.GroundLicenseMapper;
import com.weitu.worklicense.service.GroundLicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/6/9.
 */
@Service
public class GroundLicenseServiceImpl implements GroundLicenseService{
    private final GroundLicenseMapper groundLicenseMapper;
    @Autowired
    public GroundLicenseServiceImpl(GroundLicenseMapper groundLicenseMapper){
        this.groundLicenseMapper=groundLicenseMapper;
    }
    @Override
    public int queryCount(Map<String, Object> map) {
        return this.groundLicenseMapper.queryCount(map);
    }

    @Override
    public List<GroundLicense> queryList(Map<String, Object> map) {
        return this.groundLicenseMapper.queryList(map);
    }


    @Override
    @Transactional
    public boolean insertGroundLicense(GroundLicense groundLicense) {
        boolean flag=false;
        int count=this.groundLicenseMapper.insertGroundLicense(groundLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(groundLicense.getId());
        return flag&&flag2;
    }

    @Override
    public GroundLicense queryById(String id) {
        return this.groundLicenseMapper.queryById(id);
    }

    @Override
    @Transactional
    public boolean updateGroundLicense(GroundLicense groundLicense) {
        boolean flag=false;
        int count=this.groundLicenseMapper.updateGroundLicense(groundLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(groundLicense.getId());
        return flag&&flag2;
    }

    @Override
    public int deleteGround(String id) {
        return this.groundLicenseMapper.deleteGround(id);
    }

    @Override
    public int execute(String id) {
        return this.groundLicenseMapper.execute(id);
    }
}
